package com.fr.report.script.function;

import com.fr.base.core.ComparatorUtils;
import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.FArray;

public class UNIQUEARRAY extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length != 1)
      return Primitive.ERROR_VALUE;
    FArray localFArray1 = new FArray();
    for (int i = 0; i < paramArrayOfObject.length; ++i)
    {
      Object localObject = paramArrayOfObject[i];
      if (localObject instanceof FArray)
      {
        FArray localFArray2 = (FArray)localObject;
        int j = 0;
        while (true)
        {
          if (j >= localFArray2.length())
            break label109;
          if (!(isExist(localFArray1, localFArray2.elementAt(j))))
            localFArray1.add(localFArray2.elementAt(j));
          ++j;
        }
      }
      if (!(isExist(localFArray1, localObject)))
        localFArray1.add(localObject);
    }
    label109: return localFArray1;
  }

  private boolean isExist(FArray paramFArray, Object paramObject)
  {
    for (int i = 0; i < paramFArray.length(); ++i)
      if (ComparatorUtils.equals(paramFArray.elementAt(i), paramObject))
        return true;
    return false;
  }

  public Function.Type getType()
  {
    return Function.ARRAY;
  }

  public String getCN()
  {
    return "UNIQUEARRAY(array):去掉数组array中的重复元素。\n示例：\nUNIQUEARRAY([14, 2, 3, 4, 3, 2, 5, 6, 2, 7, 9, 12, 3])返回[14, 2, 3, 4, 5, 6, 7, 9, 12].";
  }

  public String getEN()
  {
    return "";
  }
}